<template>
  <div id="app" >
    <div v-if="isDevelopment">{{ pid }}</div>
    <router-view/>
  </div>
</template>

<script>

import Vue from 'vue'
import { deleteAll } from '@/utils/db'

export default {
  name: 'App',

  data() {
    return {
      pid: null,
      isDevelopment:false
    }
  },
  created() {
    this.isDevelopment = process.env.NODE_ENV !== 'production';
  },
  mounted() {
    let url = window.location.href             //获取当前url

    console.log("url",url)
    let dz_url = url.split('#')[0]                //获取#/之前的字符串

    let cs = dz_url.split('?')[1]                //获取?之后的参数字符串

    let cs_arr = cs.split('&')                    //参数字符串分割为数组

    let csobj = {}

    for (let i = 0; i < cs_arr.length; i++) {         //遍历数组，拿到json对象

      csobj[cs_arr[i].split('=')[0]] = cs_arr[i].split('=')[1]

    }

    this.pid =  csobj.pid

    Vue.prototype.pid = this.pid
    console.log('==> hello world!', this.pid)


    document.onkeydown = (event)=>{
      if(event.ctrlKey && event.shiftKey && event.altKey && event.keyCode==67 ){
        console.log("按下了CTRL+SHIFT+ALT+C","清除提示")
        this.$confirm('确认清除学习记录？', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          deleteAll().then((a,b,c,d)=>{
            console.log(a,b,c,d)
            this.$message({
              type: 'success',
              message: '删除成功!'
            });
          })
        }).catch(() => {
        });



        event.preventDefault();//取消默认行为
      }
    }

  },
  beforeDestroy() {
  }
}
</script>


<style>
/* CSS */
#app {
  height: 100vh;
}

* {
  font-family: "Microsoft YaHei";
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  height: 100vh;
}

body {
  background: radial-gradient(
      ellipse at top left,
      rgba(255, 255, 255, 1) 40%,
      rgba(229, 229, 229, .9) 100%
  );
  height: 100vh;
  -webkit-app-region: drag;
}

.el-input__inner, .el-button {
  border-radius: 0px;
}

#to_nav {
  position: fixed;
  right: 16px;
  bottom: 16px;
}
</style>
